package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC01 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] twoSum(int[] nums, int target) {
            List<Integer> res = new ArrayList<>();

            Map<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < nums.length; i++) {
                int num = nums[i];
                if (map.containsKey(target - num)) {
                    res.add(i);
                    res.add(map.get(target - num));
                } else {
                    map.put(num, i);
                }
            }

            int[] arr = new int[res.size()];
            int i = 0;
            for (Integer re : res) {
                arr[i++] = re;
            }

            return arr;
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC01 an = new LC01();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
